
bcast_url = "/broadcast";

/*
 * Check if the script is running on developing server (choose broadcast address accordingly)
 */
function isDevServer() {
	return document.URL.indexOf('127.0.0.1') != -1 || document.URL.indexOf('localhost') != -1;
}

function broadcast_location(lat, lon, speed){
	
	data = {
	    location: lat + "," + lon, 
	    user: "anon",
	    speed: speed 
	};
	
	$.getJSON(bcast_url, data, function(json){
    	//alert("JSON Data: " + json);
    });
	
}

function req_add_road(name, directions){
	
	var route = directions.routes[0].legs[0];
	var data = "name=" + name;
    
    for (var i = 0; i < route.steps.length; i++)
		for (var j = 0; j < route.steps[i].path.length; j++) {
		    latlng = route.steps[i].path[j];
		    data = data + "&path=" + latlng.lat() + "," + latlng.lng();
	    }
	
	$.post("/add_road", data, function(json){
    	alert("Added new road!");
    });
	
}
